package prime_number;

import java.util.BitSet;

/**
 * User: Vitalii Serdiuk
 * Date: 09.12.13 12:08
 */

    public class Prime {
        private  BitSet set;
        private  int size;

        public Prime(int n) {
            size = n + 1;
            set = new BitSet(size);
            set.flip(2, size);
        }

        public static void main(String[] args) {
                long start = System.nanoTime();

                Prime prime = new Prime(200000000);
                prime.sieve();
                long time = System.nanoTime() - start;
                System.out.println(time / 1000000 + " ms-seconds");

        }

        public void sieve() {
            int i = 2;
            do {
                for (int j = i*2; j < size; j += i)
                    set.clear(j);
                i = set.nextSetBit(i+1);
            } while (i > 0);
        }

        public String toString() {
            return set.toString();
        }
    }

